using System;
using System.Data;
using System.Data.SqlClient;

namespace Destra.Common.DataAccess
{
    public abstract class ReaderBase : IDataReader
    {
        private SqlDataReader m_reader;

        public ReaderBase(SqlDataReader reader)
        {
            m_reader = reader;
        }

        void IDisposable.Dispose()
        {
            Dispose(true);

            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (m_reader != null)
            {
                m_reader.Dispose();
                m_reader = null;
            }
        }

        #region IDataReader

        public int Depth
        {
            get
            {
                return m_reader.Depth;
            }
        }

        public void Close()
        {
            m_reader.Close();
        }

        public DataTable GetSchemaTable()
        {
            return m_reader.GetSchemaTable();
        }

        public bool NextResult()
        {
            return m_reader.NextResult();
        }

        public bool Read()
        {
            return m_reader.Read();
        }

        public bool IsClosed
        {
            get
            {
                return m_reader.IsClosed;
            }
        }

        public int RecordsAffected
        {
            get
            {
                return m_reader.RecordsAffected;
            }
        }

        #endregion

        #region IDataRecord

        public string GetName(int i)
        {
            return m_reader.GetName(i);
        }

        public string GetDataTypeName(int i)
        {
            return m_reader.GetDataTypeName(i);
        }

        public Type GetFieldType(int i)
        {
            return m_reader.GetFieldType(i);
        }

        public object GetValue(int i)
        {
            return m_reader.GetValue(i);
        }

        public int GetValues(object[] values)
        {
            return m_reader.GetValues(values);
        }

        public int GetOrdinal(string name)
        {
            return m_reader.GetOrdinal(name);
        }

        public bool GetBoolean(int i)
        {
            return m_reader.GetBoolean(i);
        }

        public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
        {
            return m_reader.GetBytes(i, fieldOffset, buffer, bufferoffset, length);
        }

        public byte GetByte(int i)
        {
            return m_reader.GetByte(i);
        }

        public char GetChar(int i)
        {
            return m_reader.GetChar(i);
        }

        public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
        {
            return m_reader.GetChars(i, fieldoffset, buffer, bufferoffset, length);
        }

        public Guid GetGuid(int i)
        {
            return m_reader.GetGuid(i);
        }

        public Int16 GetInt16(int i)
        {
            return m_reader.GetInt16(i);
        }

        public Int32 GetInt32(int i)
        {
            return m_reader.GetInt32(i);
        }

        public Int64 GetInt64(int i)
        {
            return m_reader.GetInt64(i);
        }

        public float GetFloat(int i)
        {
            return m_reader.GetFloat(i);
        }

        public double GetDouble(int i)
        {
            return m_reader.GetDouble(i);
        }

        public string GetString(int i)
        {
            return m_reader.GetString(i);
        }

        public decimal GetDecimal(int i)
        {
            return m_reader.GetDecimal(i);
        }

        public DateTime GetDateTime(int i)
        {
            return m_reader.GetDateTime(i);
        }

        public IDataReader GetData(int i)
        {
            return m_reader.GetData(i);
        }

        public bool IsDBNull(int i)
        {
            return m_reader.IsDBNull(i);
        }

        public int FieldCount
        {
            get
            {
                return m_reader.FieldCount;
            }
        }

        public object this[int i]
        {
            get
            {
                return m_reader[i];
            }
        }

        public object this[string name]
        {
            get
            {
                return m_reader[name];
            }
        }

        #endregion

        public SqlDataReader SqlDataReader
        {
            get
            {
                return m_reader;
            }
        }
    }
}